<template>
  <ex-dialog width="700px" class="ex-diolog" :title="title" :visible="visible" :close-on-click-modal="false"
    @closeDialog="handleClose">
    <div class="main" v-loading="loading">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" :label-width="labelWidth" class="demo-ruleForm">
        
        <el-form-item label="视频任务ID：" prop="taskId">
          <el-input type="text"   :style="{ width: inputWidth }"
            placeholder="请填写" v-model="ruleForm.taskId" clearable>
          </el-input>
        </el-form-item>
      </el-form>
    </div>
    <div class="button_box">
      <el-button type="primary" :loading="AgreeLoading" @click="submitForm('ruleForm')" v-if="id == null">确认</el-button>
      <el-button type="primary" :loading="AgreeLoading" @click="editForm('ruleForm')" v-if="id != null">确认</el-button>
      <el-button @click="handleClose">取消</el-button>
    </div>
  </ex-dialog>
</template>
<script>
import Loading from "@/components/Loading/index";
// api
import {
  bindTaskId,
} from "@/api/setting/works";

export default {
  components: {
    Loading,
  },
  props: {
    visible: Boolean,
    id: String,
    taskId:String,
  },
  data() {
    return {
      labelWidth: '120px',
      inputWidth: '300px',
      title: '绑定视频任务ID',
      loading: false,
      imgLoading: false,
      disabled: false,
      AgreeLoading: false, //按钮loading
      ruleForm: {
        id: '',//id,编辑时才传
        taskId:'',
      },
      rules: {
        taskId: [{
          required: true,
          message: "请填写视频任务ID",
          trigger: ['change', 'bulr'],
        }]
      },
    };
  },
  computed: {},
  created() {
    this.ruleForm.id = this.id
    if(this.taskId != "-")
    this.ruleForm.taskId = this.taskId
  },
  mounted() {

  },
  methods: {
    //取消
    handleClose(formName) {
      this.$emit("update:visible", false);
    },
    editForm(formName) {
      //编辑确定
      this.$refs[formName].validate((valid) => {
        if (valid) {
          //   alert("submit!");editGroupon
          this.AgreeLoading = true
          var params = {
            id: this.id,
            ...this.ruleForm,
          };
          bindTaskId(params).then((res) => {
            this.$message({
              message: "绑定成功",
              type: "success",
            });
            setTimeout(() => {
              this.$emit('success')
              this.handleClose()
              this.AgreeLoading = false
            }, 1000);
          })
            .catch(() => {
              this.AgreeLoading = false;
            });

        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};

</script>
<style lang="scss" scoped>
.ex-diolog {
  ::v-deep .ex--dialog--footer {
    border: none !important;
    padding: 0 !important;
  }

  ::v-deep .ex--dialog--main {
    padding: 10px 20px !important;
  }
}

.main {
  padding: 20px 20px;
}


.button_box {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 0;
}

</style>
